<?php
namespace backend\controllers;

use backend\components\LogBehavior;
use backend\components\PermissionAccess;
use backend\models\Permission;
use yii\grid\GridViewAsset;
use yii\web\Controller;
use yii\filters\AccessControl;

/**
 * User: Drery
 * Date: 2015/11/28
 * Time: 19:03
 */
class InitController extends Controller
{
    /* @var Permission $permission */
    public $permission;

    public $isAutoSubmit = true;

    public function actions()
    {
        return [];
    }

    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'except' => ['login', 'captcha', 'callback', 'notice', 'study-detail'],
                'rules' => [
                    [
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
                'denyCallback' => function () {
                    $this->redirect('/public/login');
                }
            ],
            'permission' => [
                'class' => AccessControl::className(),
                'except' => ['login', 'logout', 'captcha', 'profile', 'callback', 'ip', 'init', 'notice', 'study-detail'],
                'rules' => [
                    [
                        'class' => PermissionAccess::className(),
                        'allow' => true,
                    ]
                ]
            ]
        ];
    }

    public function init()
    {
        parent::init();
        \Yii::$container->set('yii\bootstrap\ActiveForm', [
            'options' => ['enctype' => 'multipart/form-data'],
            'layout' => 'horizontal',
            'fieldConfig' => [
                'template' => "{label}\n<div class=\"col-lg-6\">{input}</div>\n<div class=\"col-lg-4\">{hint}{error}</div>",
                'options' => ['class' => 'form-group'],
                'labelOptions' => ['class' => 'col-lg-2 control-label'],
                'hintOptions' => ['class' => 'hint-block']
            ],
        ]);
        if (!$this->isAutoSubmit) {
            \Yii::$container->set(GridViewAsset::className(), [
                'js' => [
                    'yii.gridView.js',
                    '/dist/js/myGridView.js'
                ]
            ]);
        }
    }
}